/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package rad.Java.MotelPlus.Views;

import rad.Java.MotelPlus.Class.Apt;
import rad.Java.MotelPlus.Class.StateApt;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.SwingConstants;
import rad.Java.MotelPlus.Class.Timmer;

/**
 * AptViews.java
 *
 * @author Renato ferreira dos santos
 * Created on 22/03/2010, 16:39:31
 */
public class AptViews extends JButton implements ActionListener{
    private Apt apt = new Apt();
    private StateApt estado;
    private changeStatusRoom dialogo;
    private Timmer t;
    private String _name;

    public AptViews()
    {
        super();
        dialogo = new changeStatusRoom();
        addActionListener(this);
    }

    public static AptViews getNovoBtn(){
        return new AptViews();
    }

    // <editor-fold defaultstate="collapsed" desc="Declaration of functions">
        public StateApt getEstado() {
            return estado;
        }

        public void setEstado(StateApt estado) {
            apt.setStatus(estado);
            this.estado = estado;
            mudarCor();
        }

        public void btnName(String name)
        {
            this.setText(name);
            this._name = name;
            
            this.setIcon(new ImageIcon("C:\\Documents and Settings\\rogerio\\Desktop\\Livre.jpg"));
            this.setHorizontalAlignment(CENTER);
            this.setHorizontalTextPosition(SwingConstants.CENTER);
            this.setVerticalAlignment(SwingConstants.TOP);
            this.setVerticalTextPosition(BOTTOM);
            
        }

        public String getNameApt()
        {
            return _name;
        }

        private void mudarCor(){
           switch (estado) {
              case Livre:
                 setIcon(new ImageIcon("images/livre.jpg"));
                 break;
              case Ocupado:
                 setIcon(new ImageIcon("images/ocupado.jpg"));
                 t = new Timmer(this);
                 t.start();
                 break;
              case Faxina:
                 setIcon(new ImageIcon("images/faxina.jpg"));
                 break;
              case Manutenção:
                 setIcon(new ImageIcon("images/manutencao.jpg"));
                 break;
              default:
                 break;
           }
        }


        public void actionPerformed(ActionEvent arg0) {
           setEstado((StateApt)dialogo.mostrar());
        }
        // </editor-fold>
}
